/**
 * 测试环境是将SSR文件编译到内存中读取，
 * 正式环境直接在磁盘上去读取
 */
const path = require('path');
const fs = require('fs');

const VueServerRenderer = require('vue-server-renderer');
const Router = require('koa-router');
const serverRender = require('./server-render');

// 直接将编译好的Manifest导入即可
const clientManifest = require('../../dist/vue-ssr-client-manifest.json');

// 获取都绘制的内容信息
const renderer = VueServerRenderer.createBundleRenderer( path.join(__dirname, '../../server-build/vue-ssr-server-bundle.json') , {
  inject: false,
  clientManifest,
});

// 获取模板
const template = fs.readFileSync(path.join(__dirname, '../server-template.ejs'), 'utf-8');

const pageRouter = new Router();

module.exports = pageRouter.get("*", async (ctx) => {
  await serverRender(ctx, renderer, template);
});